package com.enation.app.javashop.api.client;

import com.enation.app.javashop.model.promotion.coupon.dos.CouponDO;
import com.enation.app.javashop.service.promotion.coupon.CouponManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * 优惠券相关API
 *
 * @author zh create in 2018/8/6
 * @version v2.0
 * @since v7.0.0
 */
@Api(description = "优惠券相关API")
@RestController
@RequestMapping("/client/trade/coupons")
@Validated
@ApiIgnore
public class CouponClientController {


    @Autowired
    private CouponManager couponManager;

    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取优惠券对象", response = CouponDO.class)
    public CouponDO getModel(@ApiIgnore @PathVariable("id") Long id) {
        return couponManager.getModel(id);
    }

    @PostMapping(value = "/{coupon_id}/use")
    @ApiOperation(value = "使用优惠券")
    public void addReceivedNum(@PathVariable("coupon_id") Long couponId) {
        couponManager.addReceivedNum(couponId);
    }

    @PostMapping(value = "/{shop_id}/shop-name")
    @ApiOperation(value = "修改优惠券名称")
    public void editCouponShopName(@PathVariable("shop_id") Long shopId, @RequestParam("shop_name") String shopName) {
        couponManager.editCouponShopName(shopId, shopName);
    }

    @PostMapping("/{coupon_id}/use/add-num")
    public void addUsedNum(@PathVariable("coupon_id")Long id) {

        couponManager.addUsedNum(id);
    }

    @GetMapping("/seller/{seller_id}")
    public List<CouponDO> getList(@PathVariable("seller_id")Long sellerId) {
        return couponManager.getList(sellerId);
    }



}
